package com.car.carsharing.controller;

import com.car.carsharing.dto.ResponseDTO;
import com.car.carsharing.pojo.Car;
import com.car.carsharing.pojo.Pay;
import com.car.carsharing.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class PayController {

    @Autowired
    PayService payService;

    /**
     * 立即驾驶
     * @param map
     * @return
     */
    @RequestMapping("driving")
    public ResponseDTO driving(@RequestBody Map map){
        int r = payService.driving(map);
        if(r == -1){
            return new ResponseDTO().error("有车辆正在使用中");
        }
        return new ResponseDTO().success("启动成功");
    }

    /**
     * 正在使用的车辆
     * @param map
     * @return
     */
    @RequestMapping("using")
    public ResponseDTO using(@RequestBody Map map){
       Car car = payService.selectUseCar(map);
       return new ResponseDTO().success(car,"获取成功");
    }

    /**
     * 支付
     * @param map
     * @return
     */
    @RequestMapping("pay")
    public ResponseDTO pay(@RequestBody Map map){
        Pay pay = payService.updatePay(map);
        return new ResponseDTO().success(pay,"成功");
    }

    /**
     * 未支付
     * @param map
     * @return
     */
    @RequestMapping("unpay")
    public ResponseDTO unpay(@RequestBody Map map){
        Pay pay = payService.selectPay(map);
        return new ResponseDTO().success(pay,"查询成功");
    }

    /**
     * 查询车辆订单
     * @return
     */
    @RequestMapping("myPay")
    public ResponseDTO myPay(@RequestBody Integer userId){
        List<Pay> pays = payService.getMyPay(userId);
        return new ResponseDTO().success(pays,"查询成功");
    }

}
